package com.imc.platform.base.category.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.imc.core.utils.MysqlUtil;
import com.imc.platform.base.category.dao.ICategoryMapper;
import com.imc.platform.base.category.pojo.Category;
import com.imc.platform.base.menu.pojo.Menu;
import com.imc.platform.base.role.dao.IRoleMapper;
import com.imc.platform.base.role.pojo.Role;
import com.imc.platform.base.role.service.IRoleService;
import com.imc.platform.base.user.dao.mapper.IUserMapper;
import com.imc.platform.base.user.pojo.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Stream;

/*
* 类描述：分类接口实现
* 开发者：YT
* 创建日期：2018/9/14 15:42
*/
@Slf4j
@Service
@Transactional
public class CategoryServiceImpl implements ICategoryService {


    @Autowired
    private ICategoryMapper categoryMapper;

    @Autowired
    MysqlUtil mysqlUtil;

    /*
    * YT  2018/9/14 17:16
    * 方法描述：查询分类列表
    */
    @Override
    public PageInfo<Category> queryCategoryList(int pageNum, int pageSize, String qryCategoryName, String qryCategoryType) {
        PageHelper.startPage(pageNum,pageSize,true);
        PageInfo info= new PageInfo<Category>(categoryMapper.queryCategoryList(qryCategoryName,qryCategoryType));
        return info;
    }

    @Override
    public PageInfo<Category> queryCategoryByTypeOrTypeName(int pageNumber, int pageSize, String qryCategoryName, String qryCategoryType) {
        PageHelper.startPage(pageNumber,pageSize,true);
        PageInfo info= new PageInfo<Category>(categoryMapper.queryCategoryByTypeOrTypeName(qryCategoryName,qryCategoryType));
        return info;
    }

    @Override
    public int updateState(String state,String categoryId) {
        if("false".equals(state)){
            state="2";
        }else if("true".equals(state)){
            state="1";
        }
        return categoryMapper.updateState(state,categoryId);
    }

    @Override
    public int addCategory(Category bi) {
        return categoryMapper.addCategory(bi);
    }

    @Override
    public List<Category> queryCategoryExists(Map<String, String> categoryMap) {
        return categoryMapper.queryCategoryExists(categoryMap);
    }

    /**
     *QY 2018/9/3 10:15
     *方法描述：查询所有用户
     **/
    @Override
    public List<Map> queryCategoryAll(String cateType,String categoryId) {
        return categoryMapper.queryCategoryAll(cateType,categoryId);
    }

    @Override
    public int updateCategory(Map <String, String> categoryMap) {
        return categoryMapper.updateCategory(categoryMap);
    }

    @Override
    public int updateCategoryIcon(Category bi) {
        return categoryMapper.updateCategoryIcon(bi);
    }

    @Override
    public List<Menu> queryMenuByRoleIdAndMenuId(String roleId, String menuId) {
        return categoryMapper.queryMenuByRoleIdAndMenuId(roleId,menuId);
    }

    @Override
    public int delCategory(String categoryId) {
        return categoryMapper.delCategory(categoryId);
    }

    @Override
    public Category queryCategoryById(String categoryId) {
        return categoryMapper.queryCategoryById(categoryId);
    }
}
